import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 25228
 * Date: 2024-09-28
 * Time: 19:55
 */
public class Test {
    public static void main(String[] args) {
        int[] nums={1,1,2,3,3,4,5,6,5,4,6};
        String jwels="aA";
        String stones="aAAbbbb";
        //int s=singleNumber(nums);
        int s=numJewelsInStones(jwels,stones);
        System.out.println(s);
    }
    //找出只出现一次的数
    //https://leetcode.cn/problems/single-number/
    public static int singleNumber(int[] nums) {
        Map<Integer,Integer> map=new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            map.put(nums[i],map.getOrDefault(nums[i],0)+1);
        }
        for (Integer key: map.keySet()) {
            if(map.get(key)==1){
                return key;
            }
        }
        return -1;
    }
    //宝石与石头
    //https://leetcode.cn/problems/jewels-and-stones/submissions/568826626/
    public static int numJewelsInStones(String jewels, String stones) {
        Map<Character,Integer> map=new HashMap<>();
        for (int i = 0; i < jewels.length(); i++) {
            map.put(jewels.charAt(i),0);
        }
        for (int i = 0; i < stones.length(); i++) {
            if(map.containsKey(stones.charAt(i))){
                map.put(stones.charAt(i),map.get(stones.charAt(i))+1);
            }
        }
        int s=0;
        for (Character key:map.keySet()) {
            s+=map.get(key);
        }
        return s;
    }
    //坏键盘打字
    // https://www.nowcoder.com/questionTerminal/f88dafac00c8431fa363cd85a37c2d5e
    public static void bug(){
        Scanner scanner=new Scanner(System.in);
        String s1 = scanner.nextLine().toUpperCase();
        String s2 = scanner.nextLine().toUpperCase();
        Map<Character,Integer> map=new HashMap<>();
        for (int i = 0; i < s2.length(); i++) {
            map.put(s2.charAt(i),0);
        }

        StringBuilder s = new StringBuilder();
        for (int i = 0; i < s1.length(); i++) {
            if(!map.containsKey(s1.charAt(i))){
                s.append(s1.charAt(i));
                map.put(s1.charAt(i),0);
            }
        }
        System.out.println(s);
    }
}
